package com.xbfinance.portal.web;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xbfinance.common.util.PropKit;
import com.xbfinance.portal.pojo.po.BannerPic;
import com.xbfinance.portal.pojo.po.P2pProject;
import com.xbfinance.portal.service.BannerService;
import com.xbfinance.portal.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @Autowired
    private ProjectService projectService;

    @RequestMapping("/index")
    public String queryBanner(HttpSession session, @RequestParam(defaultValue="8")Integer pageSize, @RequestParam(defaultValue="1")Integer currentPage){

        Integer cid = PropKit.use("index.properties").getInt("lunbo.cid");

        List<BannerPic> bannerList = bannerService.queryBanner(cid);

        session.setAttribute("bannerList",bannerList);

        Page<Object> page = PageHelper.startPage(currentPage, pageSize);

        List<P2pProject> projectList = projectService.queryAllProject();

        PageInfo<P2pProject> pageInfo = new PageInfo<>(projectList,3);

        int[] nums = pageInfo.getNavigatepageNums();

        session.setAttribute("nums", nums);
        session.setAttribute("projectList", projectList);
        session.setAttribute("page", pageInfo);

        return "index";
    }

}
